<!--  -->
<template>
  <div class="custom-add-dialog">
    <el-dialog title="添加头部容器操作" :visible.sync="dialogFormVisible">
      <el-form :model="form" @submit.native.prevent>
        <el-form-item label="列数" :label-width="formLabelWidth" style="margin-bottom: 0px;">
          <el-input @blur="colblur" size="mini" type="number" style="width:80px;" v-model="form.col" min="1" max="8"
            placeholder="">
          </el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="mini" @click="dialogFormVisible = false">取 消</el-button>
        <el-button size="mini" type="primary" @click="submit">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import * as WindowType from '@/config/windowtype.js'
import * as PubsubType from '@/config/pubsubtype.js'
import VueFunctions from '@/core/VueFunctions.js'
import { mapState } from 'vuex'
import PubSub from 'pubsub-js'
export default {
  created () {
    VueFunctions.method(WindowType.ADD_CONTAINER_CUSTOM, (obj) => {
      this.show()
      this.form = {
        col: 1
      }
    })
  },
  mounted () {
    PubSub.subscribe(PubsubType.PUBSUB_DIGLOG_COMPONENT_AND_CONTAINER_CLOSE, (event, data) => {
      this.close()
    })
  },
  computed: {
    ...mapState([
      'design'
    ])
  },
  data () {
    return {
      dialogFormVisible: false,
      form: {
        col: 1
      },
      formLabelWidth: '120px',
      // 点击确定下的回调函数，一般都是开启编辑弹窗赋值方法函数变量
      backSuccess: null
    }
  },
  methods: {
    colblur () {
      if (this.form.col > 8) {
        this.form.col = 8
        this.form = JSON.parse(JSON.stringify(this.form))
      }
      if (this.form.col < 1) {
        this.form.col = 1
        this.form = JSON.parse(JSON.stringify(this.form))
      }
    },
    close () {
      this.dialogFormVisible = false
      if (this.backSuccess && typeof this.backSuccess === 'function') {
        this.backSuccess()
        this.backSuccess = null
      }
    },
    show () {
      this.dialogFormVisible = true
    },
    submit () {
      // 点击确定后通过 this.form 制作出一套完成的容器数据json
      this.design.ref.contentWindow.vueFunc.addContainerCustom(this.form.col)
      this.close()
    }
  }
}

</script>

<style>
.custom-add-dialog .el-dialog {
  width: 300px;
}
</style>
